package com.zb.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.zb.config.mybatisplus.MysqlInjector;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @ClassName MybatisPlusConfig
 * @Description mybatisPlus启动类
 * @Author yso
 **/
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {

  private final ApplicationContext applicationContext;

  public MybatisPlusConfig(
      ApplicationContext applicationContext) {
    this.applicationContext = applicationContext;
  }

  /**
   * 分页插件加载
   */
  @Bean
  public PaginationInterceptor paginationInterceptor() {

    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    // 设置方言
    paginationInterceptor.setDialectType(
        applicationContext.getEnvironment().getProperty("mybatis-plus.configuration.db-type"));
    return paginationInterceptor;
  }

  /**
   * 自定义sql注入（整合mybatisPlus拓展）
   */
  @Bean
  public MysqlInjector mysqlInjector() {
    return new MysqlInjector();
  }


}
